package com.ruoyi.web.controller.pv;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.pv.domain.PvHoliday;
import com.ruoyi.pv.service.IPvHolidayService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 节假日Controller
 *
 * @author zzx
 * @date 2023-07-11
 */
@RestController
@RequestMapping("/pv/holiday")
public class PvHolidayController extends BaseController {

    @Autowired private IPvHolidayService pvHolidayService;

    /**
     * 查询节假日列表
     */
    @PreAuthorize("@ss.hasPermi('pv:holiday:list')")
    @GetMapping("/list")
    public TableDataInfo list(PvHoliday pvHoliday) {
        startPage();
        List<PvHoliday> list = pvHolidayService.selectPvHolidayList(pvHoliday);
        return getDataTable(list);
    }

    /**
     * 导出节假日列表
     */
    @PreAuthorize("@ss.hasPermi('pv:holiday:export')")
    @Log(title = "节假日", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PvHoliday pvHoliday) {
        List<PvHoliday> list = pvHolidayService.selectPvHolidayList(pvHoliday);
        ExcelUtil<PvHoliday> util = new ExcelUtil<PvHoliday>(PvHoliday.class);
        util.exportExcel(response, list, "节假日数据");
    }

    /**
     * 获取节假日详细信息
     */
    @PreAuthorize("@ss.hasPermi('pv:holiday:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id) {
        return success(pvHolidayService.selectPvHolidayById(id));
    }

    /**
     * 新增节假日
     */
    @PreAuthorize("@ss.hasPermi('pv:holiday:add')")
    @Log(title = "节假日", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PvHoliday pvHoliday) {
        return toAjax(pvHolidayService.insertPvHoliday(pvHoliday));
    }

    /**
     * 修改节假日
     */
    @PreAuthorize("@ss.hasPermi('pv:holiday:edit')")
    @Log(title = "节假日", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PvHoliday pvHoliday) {
        return toAjax(pvHolidayService.updatePvHoliday(pvHoliday));
    }

    /**
     * 删除节假日
     */
    @PreAuthorize("@ss.hasPermi('pv:holiday:remove')")
    @Log(title = "节假日", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids) {
        return toAjax(pvHolidayService.deletePvHolidayByIds(ids));
    }

    /**
     * 更新今年的节假日
     */
    @PreAuthorize("@ss.hasPermi('pv:holiday:edit')")
    @Log(title = "更新今年的节假日", businessType = BusinessType.UPDATE)
    @PutMapping("/update-this-holiday")
    public AjaxResult updateThisHoliday() {
        pvHolidayService.updateThisHoliday();
        return AjaxResult.success();
    }
}
